from py_page.base_page import BasePage
from time import sleep

class MyCollectPage(BasePage):

    file_path = BasePage.get_path("./py_yaml/my_collect_page.yaml")
    # 获取收藏商品的名称列表
    def get_collect_goods_name_list(self) -> list:
        sleep(2)
        # eles = self.finds("xpath", "//*[@class='goods-name line2']")
        eles = self.run_steps(self.file_path, "get_collect_goods_name_kist")
        goods_name_list = [goods.text for goods in eles]
        return goods_name_list

    # 取消所有商品的收藏
    def cancel_all_goods_collect(self):
        sleep(2)
        # cancel_eles = self.finds("xpath", "//*[text()='取消收藏']")
        cancel_eles = self.run_steps(self.file_path, "get_all_cancel_eles")
        # confim_eles = self.finds("xpath", "//span[contains(text(),'确定')]")
        confim_eles = self.run_steps(self.file_path, "get_all_confim_eles")
        if cancel_eles:
            for index in range(len(cancel_eles)):
                cancel_eles[index].click()
                sleep(2)
                confim_eles[index].click()

        else:
            print("商品列表为空，不需要取消任何收藏")
        return self

    # 进入首页
    def goto_main_page(self):
        self.find_and_click("xpath", "//*[text()='首页']")
        from py_page.main_page import MainPage
        return MainPage(self.driver)